Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: optimize updating pools #110

Merged
merged 23 commits into from
Feb 29, 2024
Merged

fix: optimize updating pools #110

merged 23 commits into from
Feb 29, 2024

Conversation

AStox
Copy link
Contributor

@AStox AStox commented Feb 9, 2024

This PR updates the eth block handler to ignore closed loans and perform all pool updates asynchronously

@AStox AStox requested review from hieronx and filo87 February 9, 2024 05:41
filo87
filo87 previously approved these changes Feb 9, 2024
src/mappings/handlers/ethHandlers.ts Outdated Show resolved Hide resolved
src/mappings/handlers/ethHandlers.ts Outdated Show resolved Hide resolved
@@ -80,19 +82,16 @@ async function _handleEthBlock(block: EthereumBlock): Promise<void> {
}

async function updateLoans(poolId: string, blockDate: Date, shelf: string, pile: string, navFeed: string) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few remarks on the general architecture:

  1. We usually define all the required helper functions as methods inside the corresponding services... in this case the LoanService.ts would be the most appropriated.

  2. Event and Block Handlers should never set or assign directly the properties of entities (such as pools or loans) such as:

pool.totalReserve = ...

This is reserved to Service Methods only. This guarantees that the logic can be reused and maintained easily whenever the same operation occurs as a result of calls in different blocks or event handlers.

We can address this refactoring in a dedicated ticket. I will prepare a backlog item ;)

Copy link
Collaborator

@filo87 filo87 Feb 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue -> #111

amount += results.length
} while (results.length === batch)
amount += entities.length
} while (entities.length > 0)
return results
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are exactly 100 entities to query, this while loop used to enter into an infinite loop. Now, we do one extra check to make sure there are no extra entities to fetch, and if not we exit the loop.

chains-evm/eth/centrifuge.yaml Outdated Show resolved Hide resolved
src/mappings/handlers/ethHandlers.ts Outdated Show resolved Hide resolved
@hieronx hieronx merged commit 6e5026d into main Feb 29, 2024
2 of 3 checks passed
@AStox AStox deleted the optimize-eth-block-handler branch February 29, 2024 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants